#!/bin/sh
# filename: dprocessed
# description: set/unset derivation metadata 'processed' value 

#     Copyright © 2012-2013 Toan Nguyen <toan.nguyen@monash.edu>
#
#     This file is part of Xglom.
# 
#     This is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
# 
#     This is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.


# check if arguments (command) are specified
if [[ $# -eq 0 ]]; then
	echo "Error: no argument is specified."
	exit 1
fi


. dcheck

P_FLAG=

until [ -z "$1" ]
do
    case "$1" in
        "-c" | "-cid" )
        ASSET_CID=$2
        shift
        ;;
        "-p" | "-processed" )
        P_FLAG=$2
        shift
        ;;
        * )
        shift
        ;;
    esac
done

if [ -z $ASSET_CID ]
then {
    echo "Error: must input asset cid"
    exit 1;
}
fi

if [ -z $P_FLAG ]
then {
	echo "Error: must input processed flag 0 or 1"
	exit 1;
    }
else
    if [ "$P_FLAG" == "0" ]; then
	P_STRING="false"
    else
	P_STRING="true"
    fi
fi
if [ -z $P_FLAG ]
then {
	echo "Error: "
	exit 1;
    }
fi


echo $ASSET_CID
echo $P_STRING

$MFCOMMAND om.pssd.dataset.derivation.update :id "${ASSET_CID}" :processed "${P_STRING}"
